﻿@page "/lanSender"
@namespace SwashbucklerDiary.Maui.Pages
@inherits ImportantComponentBase

<MyAppBar Title="@(I18n.T("Export.Send.Name"))"
          OnClick="NavigateToBack">
</MyAppBar>

<ScrollContainer>
    <MCard Elevation="0"
           Rounded="@("lg")">
        <MList>
            <MSubheader>
                <span>
                    @(I18n.T("lanSender.List of available devices"))
                </span>
                <MSpacer></MSpacer>
                <MButton Icon="true"
                         OnClick="LANSenderService.SearchDevices">
                    <MIcon>mdi-refresh</MIcon>
                </MButton>
            </MSubheader>

            <div>
                <Virtualize Items="lanDeviceInfoListItems"
                            ItemSize="56"
                            Context="item">
                    <MListItem @key="item.IPAddress"
                               OnClick="item.OnClick">
                        <MListItemIcon>
                            <MIcon Class="list-item-icon">
                                @(item.DeviceIcon)
                            </MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <MListItemTitle>
                                @(item.DeviceName)
                            </MListItemTitle>
                            <MListItemSubtitle>
                                @(item.IPAddress)
                            </MListItemSubtitle>
                        </MListItemContent>
                    </MListItem>

                    @if (item != lanDeviceInfoListItems.Last())
                    {
                        <MDivider Class="mx-3"></MDivider>
                    }
                </Virtualize>
            </div>

            @if (LANSenderService.IsSearching)
            {
                <MListItem>
                    <MListItemIcon>
                        <MProgressCircular Size="20"
                                           Width="2"
                                           Indeterminate="true">
                        </MProgressCircular>
                    </MListItemIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            @(I18n.T("lanSender.Searching for available devices"))
                        </MListItemTitle>
                    </MListItemContent>
                </MListItem>
            }
            else
            {
                @if (lanDeviceInfoListItems.Count == 0)
                {
                    <MListItem>
                        <MListItemIcon>
                            <MIcon Class="list-item-icon">
                                mdi-close-circle-outline
                            </MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <MListItemTitle>
                                @(I18n.T("lanSender.There are currently no available devices"))
                            </MListItemTitle>
                        </MListItemContent>
                    </MListItem>
                }
            }
        </MList>
    </MCard>
</ScrollContainer>

<TransferDialog @bind-Visible="showTransferDialog"
                Title="@(I18n.T("lanSender.Sending"))"
                Ps="ps"
                Bytes="bytes"
                TotalBytes="totalBytes"
                OnCancel="CancelSend">
</TransferDialog>
